﻿using System;
using System.Collections.Generic;
using System.IO;

namespace dota2itemchanger
{
    class Item
    {
        public string name;
        public string image;
        public Item(string name, string image)
        {
            this.name = name;
            this.image = image;
        }
        public string RealImage()
        {
            string s = Directory.GetCurrentDirectory() + "\\images\\items\\" + image + ".png";
            return s;
        }
    }

    class Items
    {
        static Dictionary<string, List<Item>> items = new Dictionary<string,List<Item>>();

        public static void Load( )
        {
            StreamReader sr = new StreamReader(@"items.csv");
            char[] sep = { ';' };
            string line;
            string[] values;
            while (!sr.EndOfStream)
            {
                line = sr.ReadLine();
                values = line.Split(sep);
                if (values.Length != 3)
                {
                    continue;
                }
                if (!items.ContainsKey(values[0]))
                {
                    items[values[0]] = new List<Item>();
                }
                items[values[0]].Add(new Item(values[1], values[2]));
            }
            sr.Close();
        }

        public static Item GetItem(string name)
        {
            foreach (string s in items.Keys)
            {
                foreach (Item i in items[s])
                {
                    if (i.name == name)
                    {
                        return i;
                    }
                }
            }
            return null;
        }

        public static List<Item> AllItems()
        {
            List<Item> templist = new List<Item>();
            foreach (string s in items.Keys)
            {
                templist.AddRange(items[s]);
            }
            return templist;
        }

        public static Dictionary<string, List<Item>> GetItems()
        {
            return items;
        }

        public static List<Item> GetItemsFrom(string shop)
        {
            return items[shop];
        }
    }
}
